home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0192.ARJ / LISTS.C < prev    next >
Text File  |  1991-09-30  |  6KB  |  224 lines

  1. /* --------------- lists.c -------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. struct LinkedList Focus;
  6. struct LinkedList Built;
  7.  
  8. /* --- set focus to the window beneath the one specified --- */
  9. void SetPrevFocus(WINDOW wnd)
  10. {
  11.     if (wnd != NULL && wnd == inFocus)    {
  12.         WINDOW wnd1 = wnd;
  13.         while (TRUE)    {
  14.             if ((wnd1 = PrevWindow(wnd1)) == NULL)
  15.                 wnd1 = Focus.LastWindow;
  16.             if (wnd1 == wnd)
  17.                 return;
  18.             if (wnd1 != NULL)
  19.                 break;
  20.         }
  21.         if (wnd1 != NULL)
  22.             SendMessage(wnd1, SETFOCUS, TRUE, 0);
  23.     }
  24. }
  25.  
  26. /* this function assumes that wnd is in the Focus linked list */
  27. static WINDOW SearchFocusNext(WINDOW wnd, WINDOW pwnd)
  28. {
  29.     WINDOW wnd1 = wnd;
  30.  
  31.     if (wnd != NULL)    {
  32.         while (TRUE)    {
  33.             if ((wnd1 = NextWindow(wnd1)) == NULL)
  34.                 wnd1 = Focus.FirstWindow;
  35.             if (wnd1 == wnd)
  36.                 return NULL;
  37.             if (wnd1 != NULL)
  38.                 if (pwnd == NULL || pwnd == GetParent(wnd1))
  39.                     break;
  40.         }
  41.     }
  42.     return wnd1;
  43. }
  44.  
  45. /* ----- set focus to the next sibling ----- */
  46. void SetNextFocus(WINDOW wnd)
  47. {
  48.     WINDOW wnd1;
  49.  
  50.     if (wnd != inFocus)
  51.         return;
  52.     if ((wnd1 = SearchFocusNext(wnd, GetParent(wnd)))==NULL)
  53.         wnd1 = SearchFocusNext(wnd, NULL);
  54.     if (wnd1 != NULL)
  55.         SendMessage(wnd1, SETFOCUS, TRUE, 0);
  56. }
  57.  
  58. /* ---- remove a window from the Built linked list ---- */
  59. void RemoveBuiltWindow(WINDOW wnd)
  60. {
  61.     if (wnd != NULL)    {
  62.         if (PrevWindowBuilt(wnd) != NULL)
  63.             NextWindowBuilt(PrevWindowBuilt(wnd)) =
  64.                 NextWindowBuilt(wnd);
  65.         if (NextWindowBuilt(wnd) != NULL)
  66.             PrevWindowBuilt(NextWindowBuilt(wnd)) =
  67.                 PrevWindowBuilt(wnd);
  68.         if (wnd == Built.FirstWindow)
  69.             Built.FirstWindow = NextWindowBuilt(wnd);
  70.         if (wnd == Built.LastWindow)
  71.             Built.LastWindow = PrevWindowBuilt(wnd);
  72.     }
  73. }
  74.  
  75. /* ---- remove a window from the Focus linked list ---- */
  76. void RemoveFocusWindow(WINDOW wnd)
  77. {
  78.     if (wnd != NULL)    {
  79.         if (PrevWindow(wnd) != NULL)
  80.             NextWindow(PrevWindow(wnd)) = NextWindow(wnd);
  81.         if (NextWindow(wnd) != NULL)
  82.             PrevWindow(NextWindow(wnd)) = PrevWindow(wnd);
  83.         if (wnd == Focus.FirstWindow)
  84.             Focus.FirstWindow = NextWindow(wnd);
  85.         if (wnd == Focus.LastWindow)
  86.             Focus.LastWindow = PrevWindow(wnd);
  87.     }
  88. }
  89.  
  90. /* ---- append a window to the Built linked list ---- */
  91. void AppendBuiltWindow(WINDOW wnd)
  92. {
  93.     if (wnd != NULL)    {
  94.         if (Built.FirstWindow == NULL)
  95.             Built.FirstWindow = wnd;
  96.         if (Built.LastWindow != NULL)
  97.             NextWindowBuilt(Built.LastWindow) = wnd;
  98.         PrevWindowBuilt(wnd) = Built.LastWindow;
  99.         NextWindowBuilt(wnd) = NULL;
  100.         Built.LastWindow = wnd;
  101.     }
  102. }
  103.  
  104. /* ---- append a window to the Focus linked list ---- */
  105. void AppendFocusWindow(WINDOW wnd)
  106. {
  107.     if (wnd != NULL)    {
  108.         if (Focus.FirstWindow == NULL)
  109.             Focus.FirstWindow = wnd;
  110.         if (Focus.LastWindow != NULL)
  111.             NextWindow(Focus.LastWindow) = wnd;
  112.         PrevWindow(wnd) = Focus.LastWindow;
  113.         NextWindow(wnd) = NULL;
  114.         Focus.LastWindow = wnd;
  115.     }
  116. }
  117.  
  118. /* ---- add a window to the beginning of the Focus linked list ---- */
  119. void PrependFocusWindow(WINDOW wnd)
  120. {
  121.     if (wnd != NULL)    {
  122.         if (Focus.LastWindow == NULL)
  123.             Focus.LastWindow = wnd;
  124.         if (Focus.FirstWindow != NULL)
  125.             PrevWindow(Focus.FirstWindow) = wnd;
  126.         NextWindow(wnd) = Focus.FirstWindow;
  127.         PrevWindow(wnd) = NULL;
  128.         Focus.FirstWindow = wnd;
  129.     }
  130. }
  131.  
  132. /* -------- get the first child of a parent window ------- */
  133. WINDOW GetFirstChild(WINDOW wnd)
  134. {
  135.     WINDOW ThisWindow = Built.FirstWindow;
  136.     while (ThisWindow != NULL)    {
  137.         if (GetParent(ThisWindow) == wnd)
  138.             break;
  139.         ThisWindow = NextWindowBuilt(ThisWindow);
  140.     }
  141.     return ThisWindow;
  142. }
  143.  
  144. /* -------- get the next child of a parent window ------- */
  145. WINDOW GetNextChild(WINDOW wnd, WINDOW ThisWindow)
  146. {
  147.     if (ThisWindow != NULL)    {
  148.         do    {
  149.             if ((ThisWindow = NextWindowBuilt(ThisWindow)) !=
  150.                     NULL)
  151.                 if (GetParent(ThisWindow) == wnd)
  152.                     break;
  153.         }    while (ThisWindow != NULL);
  154.     }
  155.     return ThisWindow;
  156. }
  157.  
  158. /* -- get first child of parent window from the Focus list -- */
  159. WINDOW GetFirstFocusChild(WINDOW wnd)
  160. {
  161.     WINDOW ThisWindow = Focus.FirstWindow;
  162.     while (ThisWindow != NULL)    {
  163.         if (GetParent(ThisWindow) == wnd)
  164.             break;
  165.         ThisWindow = NextWindow(ThisWindow);
  166.     }
  167.     return ThisWindow;
  168. }
  169.  
  170. /* -- get next child of parent window from the Focus list -- */
  171. WINDOW GetNextFocusChild(WINDOW wnd, WINDOW ThisWindow)
  172. {
  173.     while (ThisWindow != NULL)    {
  174.         ThisWindow = NextWindow(ThisWindow);
  175.         if (ThisWindow != NULL)
  176.             if (GetParent(ThisWindow) == wnd)
  177.                 break;
  178.     }
  179.     return ThisWindow;
  180. }
  181.  
  182. /* -------- get the last child of a parent window ------- */
  183. WINDOW GetLastChild(WINDOW wnd)
  184. {
  185.     WINDOW ThisWindow = Built.LastWindow;
  186.     while (ThisWindow != NULL)    {
  187.         if (GetParent(ThisWindow) == wnd)
  188.             break;
  189.         ThisWindow = PrevWindowBuilt(ThisWindow);
  190.     }
  191.     return ThisWindow;
  192. }
  193.  
  194. /* ------- get the previous child of a parent window ------- */
  195. WINDOW GetPrevChild(WINDOW wnd, WINDOW ThisWindow)
  196. {
  197.     if (ThisWindow != NULL)    {
  198.         do    {
  199.             if ((ThisWindow = PrevWindowBuilt(ThisWindow)) !=
  200.                     NULL)
  201.                 if (GetParent(ThisWindow) == wnd)
  202.                     break;
  203.         }    while (ThisWindow != NULL);
  204.     }
  205.     return ThisWindow;
  206. }
  207.  
  208. /* --- bypass system windows when stepping through focus --- */
  209. void SkipSystemWindows(int Prev)
  210. {
  211.     int cl, ct = 0;
  212.     while ((cl = GetClass(inFocus)) == MENUBAR ||
  213.             cl == APPLICATION || cl == STATUSBAR)    {
  214.         if (Prev)
  215.             SetPrevFocus(inFocus);
  216.         else 
  217.             SetNextFocus(inFocus);
  218.         if (++ct == 3)
  219.             break;
  220.     }
  221. }
  222.  
  223.  
  224.